package com.baiduspring.vo;

import com.baiduspring.dao.entity.PrivateLetter;
import com.baiduspring.error.BaiduSpringException;
import com.baiduspring.utils.PreconditionsUtils;
import com.baiduspring.utils.date.DateUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;
import java.util.Objects;

/**
 * 数据传输对象
 *
 * @author xiongyan
 */
@Slf4j
@Data
//@Accessors(chain = true)
public class PrivateLetteVO implements BaseVO<PrivateLetteVO, PrivateLetter> {
    private Long id;
    private Long sender;
    private Long addressee;
    private String content;
    private Long createDate;
    private Integer show;
    private UserVO userVO;

    public String createDate() {
        return DateUtils.formatDate2String(new Date(this.createDate), "yyyy-MM-dd HH:mm:ss");
    }

    @Override
    public PrivateLetteVO validate() {
        PreconditionsUtils.checkArgument(Objects.nonNull(this.sender), "发件人不能为空");
        PreconditionsUtils.checkArgument(Objects.nonNull(this.addressee), "收件人不能为空");
        PreconditionsUtils.checkArgument(Objects.nonNull(this.content), "私信内容不能为空");
        PreconditionsUtils.checkArgument(!this.sender.equals(this.addressee), "不能自己给自己发私信");

        int length = 500;
        if (this.content.length() > length) {
            throw new BaiduSpringException("信息内容大小不能超过500个字");
        }

        return this;
    }
}
